package com.fjw.controller;

import com.fjw.pojo.Order;
import com.fjw.pojo.Result;
import com.fjw.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    public Result createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return Result.success();
    }

    @GetMapping("/findById")
    public Result<Order> findById(@RequestParam Integer id) {
        Order order = orderService.findById(id);
        return Result.success(order);
    }

    @GetMapping("/findByUserId")
    public Result<List<Order>> findByUserId(@RequestParam Integer userId) {
        List<Order> orders = orderService.findByUserId(userId);
        return Result.success(orders);
    }

    @GetMapping("/findAll")
    public Result<List<Order>> findAll() {
        List<Order> orders = orderService.findAll();
        return Result.success(orders);
    }

    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestParam Integer id, @RequestParam Integer status) {
        orderService.updateStatus(id, status);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Integer id) {
        orderService.deleteById(id);
        return Result.success();
    }
}